<?php

/**
 * Created by PhpStorm.
 * User: d7
 * Date: 2016/1/27
 * Time: 11:04
 */
class Place extends MY_Pc_Api_Controller
{
    protected $_page_size;
    function __construct(){
        parent::__construct();
        $this->_page_size = $this->config->item('page_size','default');
    }


    function gets(){
        $this->load->model('place/Place_model');
        $page = $this->input->get('page');
        $page = $page>0 ? $page : 1;
        $field  = $this->input->get('field');
        $field  = empty($field)?'id':$field;
        $sort   = $this->input->get('sort')=='asc'?'asc':'desc';
        $status = $this->input->get('status');
        $condition = array(
            'is_del'    =>  0,
        );
        if($status!=='' or $status!==null)
            $condition['status'] = $status;
        $options = array(
            'limit' =>array(
                $this->_page_size,
                ($page-1)*$this->_page_size
            ),
            'order'=>
                array($field.' '.$sort)
        );
        $places = $this->Place_model->fetch_array($condition,'name,avatar,intro,score',$options);
        if(!$places){
            $this->json_response(false);
        }
        $this->json_response(true,$places);
    }

    function get(){
        $id = $this->input->get('id');
        if($id<0){
            $this->json_response(false);
        }
        $place = $this->Place_model->getOne(array('id'=>$id));
        if(!$place)
            $this->json_response(false);
        $this->json_response(true,$place);
    }

    function get_comments(){
        $this->json_response(false);
        //todo:  next
    }
}